package org.study.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import org.study.dao.IUserDaoRedis;
import org.study.entity.User;

/**
 * @author 627266
 * @version 2017年1月12日 下午3:06:09
 * @comment
 */
@Repository(value = "userDaoReids")
public class UserDaoRedis implements IUserDaoRedis {

	@Autowired
	private RedisTemplate<String, User> redisTemplate;

	@Override
	public void saveUser(User user) {
		// redisTemplate.execute(new RedisCallback<Object>() {
		// @Override
		// public String doInRedis(RedisConnection connection) throws
		// DataAccessException {
		// connection.exists(redisTemplate.getStringSerializer().serialize("key"));
		// return null;
		// }
		// });
		boolean key = redisTemplate.hasKey(user.getObjectKey());
		boolean hashkey  =redisTemplate.opsForHash().hasKey(user.getObjectKey(), 1L);
		System.out.println(key);
		redisTemplate.opsForHash().put(user.getObjectKey(), user.getKey(), user);
		redisTemplate.opsForSet().add("userset",user);
		
	}

	@Override
	public void saveUserList(List<User> user) {

	}

	@Override
	public User getUser(Long key) {
		User user = (User) redisTemplate.opsForHash().get(User.OBJECTKEY, Long.valueOf(key));
		redisTemplate.opsForSet().members("userset");
		return user;
	}
}
